using UnityEngine;
using System.Collections;

public class cTrackChecker : MonoBehaviour {
	
	public cCourse []CourseList;
	public cCourse Goal;
	
	public int CurrentCourseNo;
	public bool bAllClear = false;
	public int LabCounter;
	
	public float LabTime;
	public float LastLabTime;

	// Use this for initialization
	void Start () {
	
		bAllClear = false;
		LabCounter = 0;
		LabTime = 0f;
		LastLabTime = 0f;
	}
	
	void InitCourse()
	{
		
		// 시작하기전 첫 코스를 빼고 disable 시킨다.
		foreach ( cCourse course in CourseList )
		{
			
			course.enabled = false;
			course.bPassCourse = false;
			
		}
		
		CurrentCourseNo = 0;
		
		CourseList[ CurrentCourseNo ].enabled = true;
		
		Goal.enabled = false;
		Goal.bPassCourse = false;
		
	}
	
	// Update is called once per frame
	void Update () {
	
		LabTime += Time.deltaTime;
		
		if ( CourseList.Length > 0 && CourseList.Length > CurrentCourseNo )
		{
			if ( CourseList[CurrentCourseNo].bPassCourse )
			{
				
				CourseList[CurrentCourseNo].enabled = false;
				
				CurrentCourseNo++;
				
				if ( CourseList.Length > CurrentCourseNo )
					
					CourseList[CurrentCourseNo].enabled = true;
				
			}
			
			if ( CurrentCourseNo >= CourseList.Length )
			{
				
				bAllClear = true;
				
				Goal.enabled = true;
//				CourseClear();
				
			}
			
		}
		
		if ( bAllClear && Goal.bPassCourse )
		{
			
			bAllClear = false;
			
			CourseClear();
			
			LabCounter++;
			
			CurrentCourseNo = 0;
			
			LastLabTime = LabTime;
			
			LabTime = 0f;
		}
		else
			
			Goal.bPassCourse = false;
		
	}
	
	void CourseClear()
	{
		
		foreach ( cCourse course in CourseList )
		{
			
			course.bPassCourse = false;
			
		}
		
		CurrentCourseNo = 0;
		
		CourseList[CurrentCourseNo].enabled = true;
		
	}
	
}
